<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">
<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title">
        <div class="page-title-con">
            <span id="flowsetname"></span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <button type="button" class="layui-btn layui-btn-sm btn-light marginr5" onclick="check_bid()">从中标项目引入</button>
                <button type="button" class="layui-btn layui-btn-sm btn-light marginr5" id="billzhan" but="1" key="0" lay-submit="" lay-filter="add">暂存</button>
                <button type="button" class="layui-btn layui-btn-sm btn-light marginr5" id="billtutn" but="2" key="0" lay-submit="" lay-filter="add">保存草稿</button>
                <button type="button" class="layui-btn layui-btn-sm btn-dark marginr5" but="3" key="1" id="billsub" isshen="0" lay-submit="" lay-filter="add">提交审核</button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请人</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowuser" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请部门</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowdept" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" id="number" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目属性</label>
                        <div class="layui-input-block ">
                            <div class="radio-block">
                                <input type="radio" class="business1" name="business" lay-filter="business" value="1" title="自营" disabled>
                                <input type="radio" class="business2" name="business" lay-filter="business" value="2" title="联营" disabled>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目类型</label>
                        <div class="layui-input-block">
                            <div id="engintype"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="lian_unitDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>联营方</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="lian_unit" class="layui-input lian_unit" onclick="openPage('../public/choose_dealcom.php?dom=lian_unit','80%','80%')">
                            <div class="choose_div" id="lian_unit" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=lian_unit','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">建设单位</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="jian_unit" class="layui-input jian_unit" onclick="openPage('../public/choose_dealcom.php?dom=jian_unit','80%','80%')">
                            <div class="choose_div" id="jian_unit" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=jian_unit','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>所属单位</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=chanid&type=dept&dept=chan&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="chanid"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=chanid&type=dept&dept=chan&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="chanid_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">所在地</label>
                        <div class="layui-input-block" style="z-index: 1;">
                            <input type="text" name="areas" id="areas" placeholder="请选择" readonly clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">详细地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="addr" id="addr" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程造价(万元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="expectfee" id="expectfee" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput6">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工期(天)</label>
                        <div class="layui-input-block">
                            <input type="text" name="duration" id="duration" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">计划开工日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="startdt" id="startdt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">计划竣工日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="enddt" id="enddt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">招标方式</label>
                        <div class="layui-input-block">
                            <div id="zhaotype"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目状态</label>
                        <div class="layui-input-block">
                            <select id="state" name="state" lay-filter="state" ></select>
                            <p class="error" id="state_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>项目负责人</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=man_xiang&type=user&single=1', '770px', '490px');"></div>
                                <div class="tanxiannei" id="man_xiang"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=man_xiang&type=user&single=1', '770px', '490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="man_xiang_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>

                </div>
            </div>

            <div class="layui-form-item layui-hide" id="actualdtDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>实际开工日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="actualdt" id="actualdt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="filishdtDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>竣工验收日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="filishdt" id="filishdt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">关联单据</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="flowrelas" class="layui-input flowrelas" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');">
                            <div class="choose_div" id="flowrelas" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="advanersDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">预审人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"></div>
                                <div class="tanxiannei" id="advaners"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item layui-hide" id="nexterDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>指定下一步审核人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="nexter"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>

        </div>
    </div>
</form>
<script>

    var param_business = getQueryVariable('business') || '';
    if(param_business == 1){
        $(".business1").prop('checked', true);
    }else  if(param_business == 2){
        $(".business2").prop('checked', true);
        $("#lian_unitDiv").removeClass('layui-hide');
    }else{
        $(".business1").prop('checked', true);
        $(".business1").prop('disabled', false);
        $(".business2").prop('disabled', false);
    }


    $("#commentForm").validate({
        rules: {
            name: {required: true},
            actualdt: {required: true},
            filishdt: {required: true},
        },
        messages:{
            name: {required: "请输入"},
            actualdt: {required: "请选择"},
            filishdt: {required: "请选择"},
        }
    });


    function check_bid () {
        openPage('../public/choose_bid.php?dom=bidid&page=engin&state=3&business='+param_business,'80%','80%');
    }


    var pub_areas = [];
    var pub_engintype = [];
    var pub_zhaotype = [];
    function show_areas (value=''){
        $("#areas").val(value);
        $(".city-picker-span").remove();
        $(".city-picker-dropdown").remove();
        $(".input-attr-close-icon").remove();
        load_areas('areas', pub_areas, 3);
    }
    function show_engintype(value=''){
        xmselect_dan('engintype', pub_engintype, value);
    }
    function show_zhaotype(value=''){
        xmselect_dan('zhaotype', pub_zhaotype, value);
    }

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_flowdata_add_engin}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;
                $("#flowsetname").text(data.flowsetname);
                $("#flowuser").val(data.flowuser);
                $("#flowdept").val(data.flowdept);
                if(data.isadvan){
                    $("#advanersDiv").removeClass('layui-hide');
                }
                if(data.isnext){
                    $("#nexterDiv").removeClass('layui-hide');
                }

                pub_areas = res.data.areas
                pub_engintype = res.data.engintype
                pub_zhaotype = res.data.zhaotype
                show_areas();
                show_engintype();
                show_zhaotype();


                var state_str = '<option value="">请选择</option>';
                var state = res.data.state;
                for (var key in state){
                    state_str += '<option value="'+key+'">'+state[key]+'</option>';
                }
                $("#state").html(state_str);


                public_upload_file_load('upload_files');
                render_date();
                render_from();
                initParseMoney();
            }
        });

        form.on('radio(business)', function(data){
            if(data.value == 1){
                $(".business1").prop('checked', true);
                $("#lian_unitDiv").addClass('layui-hide');
            }else{
                $(".business2").prop('checked', true);
                $("#lian_unitDiv").removeClass('layui-hide');
            }


        });

        form.on('select(state)', function(data){
            if(data.value == ''){
                $('#state_error').show().text('请选择');
                $('#state_error').parent().find('input').addClass('select_error');
            }else{
                $('#state_error').hide();
                $('#state_error').parent().find('input').removeClass('select_error');
            }

            if(data.value == 3){
                $("#actualdtDiv").removeClass('layui-hide');
                $("#filishdtDiv").addClass('layui-hide');
            }else if(data.value == 6){
                $("#actualdtDiv").removeClass('layui-hide');
                $("#filishdtDiv").removeClass('layui-hide');
            }else{
                $("#actualdtDiv").addClass('layui-hide');
                $("#filishdtDiv").addClass('layui-hide');
            }

        });



        form.on('submit(add)', function(data){
            data.field.isturn = $(this).attr('key') || 0;
            data.field.flowrelas = get_choose_val('flowrelas');
            data.field.advaners = tan_tags_getvalue("#advaners", 'user');
            data.field.nexter = tan_tags_getvalue("#nexter", 'user');


            data.field.lian_unit = get_choose_val('lian_unit');
            data.field.jian_unit = get_choose_val('jian_unit');
            data.field.chanid = tan_tags_getvalue("#chanid", 'dept');
            data.field.man_xiang = tan_tags_getvalue("#man_xiang", 'user');

            if(data.field.isturn > 0){
                var validRes = $("#commentForm").valid();
                if(data.field.business == 2){

                    formValid('lian_unit');
                    if(data.field.lian_unit == undefined || !data.field.lian_unit){
                        validRes = false;
                    }
                }

                if(!data.field.chanid){
                    $("#chanid").parents('.tanxian').addClass('tanerror');
                    $('#chanid_tanerror').text('请选择');
                    validRes = false;
                }else{
                    $("#chanid").parents('.tanxian').removeClass('tanerror');
                    $('#chanid_tanerror').text('');
                }

                if(data.field.state == ''){
                    $('#state_error').show().text('请选择');
                    $('#state_error').parent().find('input').addClass('select_error');
                    validRes = false;
                }else{
                    $('#state_error').hide();
                    $('#state_error').parent().find('input').removeClass('select_error');
                }


                if(!data.field.man_xiang){
                    $("#man_xiang").parents('.tanxian').addClass('tanerror');
                    $('#man_xiang_tanerror').text('请选择');
                    validRes = false;
                }else{
                    $("#man_xiang").parents('.tanxian').removeClass('tanerror');
                    $('#man_xiang_tanerror').text('');
                }

                if(!validRes){return false;}
            }



            data = parseMoney(data);
            data.field.files = public_upload_file_value('upload_files');
            public_flow_submit(data.field, ask_flowdata_add_engin, ask_flowdata_edit_engin, $(this).attr('but'));
            return false;
        });

    });

</script>
</body>
</html>
